package com.gouaixin.bee.beeframework2.dao;

import android.content.Context;

import com.google.gson.Gson;
import com.gouaixin.bee.beeframework2.bean.ServiceMsg;
import com.gouaixin.bee.beeframework2.tool.mLog;
import com.lidroid.xutils.DbUtils;
import com.lidroid.xutils.db.sqlite.Selector;
import com.lidroid.xutils.exception.DbException;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2015/4/23.
 */
//缘分小秘书的数据库操作器
public class ServiceMsgDao {


    public static void add(Context context, ServiceMsg bean){
        try {
            mLog.e("开始执行：ServiceMsgDao.add");
            //DbUtils db = DbUtils.create(this.getActivity(), "/sdcard/", "test.db");
            DbUtils db = DbUtils.create(context);
            db.configAllowTransaction(true);
            db.configDebug(true);

            db.saveBindingId(bean);
            mLog.e("开始执行：ServiceMsgDao.add");
            mLog.e("执行完毕：ServiceMsgDao.add");
        } catch (DbException e) {
            mLog.e("执行出错：ServiceMsgDao.add=" + e.getMessage());
        }
    }





    public static List<ServiceMsg> query(Context context){
        List<ServiceMsg> list =new ArrayList<ServiceMsg>();

        try {
            mLog.e("开始执行：ServiceMsgDao.query");
            //DbUtils db = DbUtils.create(this.getActivity(), "/sdcard/", "test.db");
            DbUtils db = DbUtils.create(context);
            db.configAllowTransaction(true);
            db.configDebug(true);


            list = db.findAll(Selector.from(ServiceMsg.class));//.where(WhereBuilder.b("name", "=", "child' name")));
            mLog.e("执行完毕：ServiceMsgDao.query=" + new Gson().toJson(list));
        } catch (DbException e) {
            mLog.e("执行出错：ServiceMsgDao.query=" + e.getMessage());
        }

        return list;
    }


}
